package com.crawler.harbour.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.crawler.harbour.model.Shipment;
import com.crawler.harbour.model.ShipmentHyg;

import java.util.Map;

public class MapToBeanUtil {


    public static Shipment shipment(Map<String,Object> dataMap){
        Shipment shipment = new Shipment();
        shipment.setAgent(getMapData(dataMap,"agent"));
        shipment.setBerthingDate(getMapDataDate(dataMap,"berthing_date"));
        shipment.setCustCutDate(getMapDataDate(dataMap,"cust_cut_date"));
        shipment.setCyCutDate(getMapDataDate(dataMap,"cy_cut_date"));
        shipment.setCyRcvDate(getMapDataDate(dataMap,"cy_rcv_date"));
//        String domain = getMapData(dataMap,"domain");
//        if(domain.equals("FIC")){
//            shipment.setDomain("江阴港");
//        }else if(domain.equals("FQC")){
//            shipment.setDomain("青州港");
//        }
        shipment.setWharfName(getMapData(dataMap,"domain"));
        shipment.setEta(getMapData(dataMap,"eta"));
        shipment.setGrsTonnage(getMapData(dataMap,"grs_tonnage"));
        shipment.setInVvd(getMapData(dataMap,"in_vvd"));
        shipment.setLiner(getMapData(dataMap,"liner"));
        shipment.setLstTxDate(getMapDataDate(dataMap,"lst_tx_date"));
        shipment.setNationality(getMapData(dataMap,"nationality"));
        shipment.setNextPort(getMapData(dataMap,"next_port"));
        shipment.setOutVvd(getMapData(dataMap,"out_vvd"));
        shipment.setPrevPort(getMapData(dataMap,"prev_port"));
        shipment.setRemark(getMapData(dataMap,"remark"));
        shipment.setSailingDate(getMapDataDate(dataMap,"sailing_date"));
        String status = getMapData(dataMap,"status");
        switch (status){
            case "Y":
                shipment.setStatus("已离港");
                break;
            case "U":
                shipment.setStatus("未开户");
                break;
            case "E":
                shipment.setStatus("已开户");
                break;
        }
        shipment.setSvcName(getMapData(dataMap,"svc_name"));
        shipment.setTareTonnage(getMapDataDate(dataMap,"tare_tonnage"));
        String trade = getMapData(dataMap,"trade");
        if(trade.equals("0")){
            shipment.setTrade("内贸");
        }else {
            shipment.setTrade("外贸");
        }
        shipment.setVslLen(getMapData(dataMap,"vsl_len"));
        shipment.setVslNameCn(getMapData(dataMap,"vsl_name_cn"));
        shipment.setVslNameEn(getMapData(dataMap,"vsl_name_en"));
        shipment.setXzCutDate(getMapDataDate(dataMap,"xz_cut_date"));
        return shipment;
    }

    public static ShipmentHyg shipmentHyg(Map<String,Object> dataMap){
        ShipmentHyg shipmentHyg = new ShipmentHyg();
        shipmentHyg.setHideShip(getMapData(dataMap,"隐藏船期"));
        shipmentHyg.setShipment(getMapData(dataMap,"船期"));
        shipmentHyg.setShipName(getMapData(dataMap,"船名"));
        shipmentHyg.setShipTime(getMapData(dataMap,"航次"));
        shipmentHyg.setTradeAttribute(getMapData(dataMap,"贸易属性"));
        shipmentHyg.setShipLine(getMapData(dataMap,"航线"));
        shipmentHyg.setEntryTime(getMapData(dataMap,"可进场时间"));
        shipmentHyg.setCutOffTime(getMapData(dataMap,"截箱时间"));
        shipmentHyg.setCutDanTime(getMapData(dataMap,"截单时间"));
        shipmentHyg.setBerthingTime(getMapData(dataMap,"预计靠泊时间"));
        shipmentHyg.setUnberthingTime(getMapData(dataMap,"预计离泊时间"));
        return shipmentHyg;
    }

    public static String getMapData(Map map,String key){
        return map.get(key)==null?"":map.get(key).toString();
    }

    public static String getMapDataDate(Map map,String key){
        String mapStr = getMapData(map,key);
        if(StrUtil.isEmpty(mapStr)){
            return "";
        }else {
            return DateUtil.formatDateTime(DateUtil.date(Long.valueOf(mapStr)));
        }
    }

}
